﻿using System;
using System.Collections.Generic;
using System.Linq;

using NUnit.Framework;

using UniversalApproach.Expands;

namespace NUnitTestProject1
{
    [TestFixture]
    public class ObjectExpandTest2
    {
        //[Test]
        [Ignore("通过")]
        public void Test()
        {
            var user = new TestDeepModel
            {
                UserInfo = new UserInfo()
                {
                    Age = 30,
                    Height = 170D,
                    NickName = "333",
                    Wight = 120D
                },
                Address = new Address()
                {
                    Name = "林坊",
                    AddressDeepInfo = new AddressDeepInfo()
                    {
                        City = "福建",
                        PostalCode = "350825",
                        Region = "222",
                    },
                    AddressDescription = "一个镇子",
                    AddressType = "镇",
                },
                Description = "这是一个人",
                Name = "林",
                Phone = "111",
                DateTime = DateTime.Now,
            };

            var pathName = "Name";
            var pathName1 = "UserInfo.Age";
            var pathName2 = "Address.Name";
            var pathName3 = "Address.AddressDeepInfo.City";


            var propertiesList = user.GetPropertiesByDeep();

            var deepProperty = propertiesList.FirstOrDefault(s => s.FullName == pathName2);
            var userValue = ObjectExpand.GetValue(deepProperty, user);
            Assert.IsTrue(userValue.ToString() == "林坊");
        }

        [Test]
        //[Ignore("通过")]
        public void Test2()
        {
            var user = new TestPropertiesInfo
            {
                DateTimeInfo = DateTime.Now,
                DateTimeOffsetInfo = new DateTimeOffset(DateTime.Now),
                TestPropertiesItemInfo = new TestPropertiesItemInfo(),
                TestPropertiesItemInfos = new List<TestPropertiesItemInfo>(),
                DecimalInfo = 1.1M,
                DoubleInfo = 2.2222D,
                DoubleListInfo = new List<double>(),
                DynamicInfo = "111",
                FloatInfo = 1.1222F,
                Int16Info = 32,
                Int32Info = 64,
                Int64Info = 128,
                ListIntInfo = new List<int>(),
                StrInfo = "2222",
                StrListInfo = new List<string>(),
            };

            var pathName = "DynamicInfo";


            var propertiesList = user.GetPropertiesByDeep();

            var deepProperty = propertiesList.FirstOrDefault(s => s.FullName == pathName);
            var userValue = ObjectExpand.GetValue(deepProperty, user);
            Assert.IsTrue(userValue.ToString() == "111");
        }
    }


    public class TestDeepModel
    {
        public string Name { get; set; }

        public string Description { get; set; }

        public string Phone { get; set; }

        public Address Address { get; set; }

        public UserInfo UserInfo { get; set; }

        public DateTime DateTime { get; set; }
    }

    public class TestPropertiesInfo
    {
        public string StrInfo { get; set; }

        public double DoubleInfo { get; set; }

        public float FloatInfo { get; set; }

        public decimal DecimalInfo { get; set; }

        public dynamic DynamicInfo { get; set; }

        public short Int16Info { get; set; }

        public int Int32Info { get; set; }

        public long Int64Info { get; set; }

        public DateTime DateTimeInfo { get; set; }

        public DateTimeOffset DateTimeOffsetInfo { get; set; }

        public List<int> ListIntInfo { get; set; }

        public List<string> StrListInfo { get; set; }

        public List<double> DoubleListInfo { get; set; }

        public List<TestPropertiesItemInfo> TestPropertiesItemInfos { get; set; }

        public TestPropertiesItemInfo TestPropertiesItemInfo { get; set; }
    }

    public class TestPropertiesItemInfo
    {
        public string StrInfo { get; set; }

        public int IntInfo { get; set; }
    }

    public class UserInfo
    {
        public string NickName { get; set; }

        public int Age { get; set; }

        public double Wight { get; set; }

        public double Height { get; set; }
    }

    public class AddressDeepInfo
    {
        public string City { get; set; }

        public string Region { get; set; }

        public string PostalCode { get; set; }
    }


    public class Address
    {
        public string Name { get; set; }

        public string AddressType { get; set; }

        public string AddressDescription { get; set; }

        public AddressDeepInfo AddressDeepInfo { get; set; }
    }
}